package river_city_ransom.contracts;

import exceptions.ComposantError;
import exceptions.PostconditionError;
import exceptions.PreconditionError;
import river_city_ransom.decorators.Bloc_D;
import river_city_ransom.services.Bloc;
import river_city_ransom.services.Position;
import river_city_ransom.types.BlocType;
import tools.Toolbox;

public class Bloc_C extends Bloc_D {
	public Bloc_C(Bloc delegate) {
		super(delegate);
	}
	
	@Override
	public String toString() {
		return super.toString();
	}
	
	/** _________________________________________________________ OBSERVATORS */
	@Override
	public BlocType type() {
		return super.type();
	}

	@Override
	public Position position() {
		return super.position();
	}
	
	/** ________________________________________________________ CONSTRUCTORS */
	@Override
	public void init(BlocType bt, Position p) throws ComposantError {
		boolean pre;
		
	//  pre init(bt, p) require bt != NULL ^ p != NULL
		pre =  bt != null ^ p != null;
		if(!pre) {
			throw new PreconditionError("init(bt, p) require bt != NULL ^ p != NULL");
		}
		
		super.init(bt, p);
		
		boolean post;
//		post type(init(bt, p)) = bt
		post = type() == bt;
		if(!post) {
			throw new PostconditionError("post type(init(bt, p)) = bt");
		}
	//  post position(init(bt, p)) = p
		post = Toolbox.equals(position() , p);
		if(!post) {
			throw new PostconditionError("post position(init(bt, p)) = p");
		}
		
	}
}
